package com.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CompletableFutureDemo {

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 20, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
		CompletableFuture<Void> future1 = CompletableFuture.runAsync(()->{
			System.out.println(Thread.currentThread().getName() + "\t" + "-- come in");
		});
		System.out.println(future1.get());
		CompletableFuture<Void> future2 = CompletableFuture.runAsync(()->{
			System.out.println(Thread.currentThread().getName() + "\t" + "--- come in");
		}, executor);
		System.out.println(future2.get());
		CompletableFuture<Integer> future3 = CompletableFuture.supplyAsync(()->{
			System.out.println(Thread.currentThread().getName() + "\t" + "-- come in");
			return 11;
		});
		System.out.println(future3.get());
		CompletableFuture<Integer> future4 = CompletableFuture.supplyAsync(()->{
			System.out.println(Thread.currentThread().getName() + "\t" + "-- come in");
			return 12;
		},executor);
		System.out.println(future4.get());
		executor.shutdown();
	}
}
